<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>signature生成器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 80%;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        form {
            padding: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input, textarea {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        input[type="submit"], .return-link {
            display: inline-block;
            padding: 10px 20px; /* 按钮变大 */
            background-color: #007BFF;
            color: #fff;
            text-decoration: none;
            border: none;
            border-radius: 5px;
            margin: 10px;
            font-size: 16px; /* 按钮变大 */
        }
        input[type="submit"]:hover, .return-link:hover {
            background-color: #0056b3;
        }
        #response {
            margin-top: 20px;
            width: 100%; /* 使其与输入框同宽 */
            word-wrap: break-word; /* 支持自动换行 */
        }
    </style>
</head>
<body>
<div class="container">
    <a href="/test/index" class="return-link"> 返回 </a>
    <h1>signature生成器</h1>
    <form id="myForm">
        <label for="token">token :<br>（系统分配的开发者令牌）</label>
        <input type="text" id="token" name="token"><br><br>

        <label for="tm">tm :<br>（时间戳）</label>
        <input type="text" id="tm" name="tm"><br><br>

        <label for="nonce">nonce :<br>（随机字符）</label>
        <input type="text" id="nonce" name="nonce"><br><br>

        <input type="submit" value="提交">
    </form>
    <div id="response">
        <!-- 这里显示响应数据 -->
    </div>
</div>

<script>
    const form = document.getElementById("myForm");
    const responseDiv = document.getElementById("response");

    form.addEventListener("submit", function(event) {
        event.preventDefault();

        const formData = new FormData(form);
        const requestBody = {};

        formData.forEach((value, key) => {
            requestBody[key] = value;
        });

        fetch("/debug/signature", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(requestBody)
        })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    responseDiv.innerHTML = data.data.signature;
                } else {
                    responseDiv.innerHTML = "请求失败：Code " + data.msg;
                }
            })
            .catch(error => {
                responseDiv.innerHTML = "请求失败：" + error;
            });
    });
</script>
</body>
</html>
